<!doctype html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"
          integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"
            integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
            crossorigin="anonymous"></script>
    <style>
        table {
            width: 100%;
        }
    </style>
    <title>Monitor</title>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-lg-2"></div>
        <div class="col-lg-8">
            <table class="table table-striped table-hover table-bordered">
                <thead>
                <tr>
                    <td>节点名</td>
                    <td>文件数目</td>
                    <td>空闲空间</td>
                    <td>总容量</td>
                    <td>节点ip</td>
                </tr>
                </thead>
                <tbody class="nodes">

                </tbody>
            </table>
            <table class="table table-striped table-hover table-bordered">
                <thead>
                <tr>
                    <td>文件名</td>
                    <td>uuid</td>
                    <td>md5</td>
                    <td>服务器</td>
                    <td>备份服务器</td>
                    <td>字节数</td>
                </tr>
                </thead>
                <tbody class="files">

                </tbody>
            </table>
        </div>
        <div class="col-lg-2"></div>
    </div>
</div>
<script>
    function getDataByMonitor() {
        $.ajax("http://localhost:8080/index.jsp", {
            type: "GET",
            success: function (data) {
                var jsonData = JSON.parse(data);
                var nodes = jsonData.nodesData;
                var files = jsonData.filesData;
                $('.nodes').text("");
                nodes.forEach(function (node) {
                    $('.nodes').append("<tr>" +
                        "<td>" + node.name +
                        "</td><td>" + node.fileNum +
                        "</td><td>" + node.spareSpace +
                        "</td><td>" + node.totalVolume +
                        "</td><td>" + node.ip +
                        "</td></tr>");
                });
                $('.files').text("");
                files.forEach(function (file) {
                    $('.files').append("<tr>" +
                        "<td>" + file.fileName +
                        "</td><td>" + file.uuid +
                        "</td><td>" + file.md5 +
                        "</td><td>" + file.serverName +
                        "</td><td>" + file.backupServerName +
                        "</td><td>" + file.length +
                        "</td></tr>");
                });
            }
        });
    }
    getDataByMonitor();
    setInterval(function () {
        getDataByMonitor();
    }, 5000);

</script>
</body>
</html>